        var carouselInner = document.querySelector('.carousel-inner');
        var slides = carouselInner.querySelectorAll('img');
        var indicators = document.querySelectorAll('.carousel-indicator');
        var prevButton = document.querySelector('.prev');
        var nextButton = document.querySelector('.next');

        // 初始化当前幻灯片索引
        var currentSlideIndex = 0;

        // 函数：切换到指定索引的幻灯片
        function switchSlide(index) {
            // 移除所有幻灯片的'active'类
            slides.forEach((slide, idx) => {
                slide.classList.remove('active');
                indicators[idx].classList.remove('active');
            });
            // 给当前幻灯片和对应的指示器添加'active'类
            slides[index].classList.add('active');
            indicators[index].classList.add('active');
            currentSlideIndex = index; // 更新当前幻灯片索引
        }

        // 向前和向后切换幻灯片的函数
            function nextSlide() {
        if (currentSlideIndex === slides.length - 1) {
            switchSlide(0);
            scrollToSlide(0);
        } else {
            var nextIndex = (currentSlideIndex + 1) % slides.length;
            switchSlide(nextIndex);
            scrollToSlide(nextIndex);
        }
    }

    // 向后切换幻灯片的函数，保持不变
    function prevSlide() {
        var prevIndex = (currentSlideIndex - 1 + slides.length) % slides.length;
        switchSlide(prevIndex);
        scrollToSlide(prevIndex);
    }
        // 滚动到指定幻灯片的函数
        function scrollToSlide(index) {
            var slideWidth = carouselInner.querySelector('img').clientWidth;
            carouselInner.scrollTo({
                left: slideWidth * index,
                behavior: 'smooth' // 平滑滚动
            });
        }

        // 绑定按钮点击事件
        prevButton.addEventListener('click', prevSlide);
        nextButton.addEventListener('click', nextSlide);

        // 指示器点击事件
        indicators.forEach((indicator, index) => {
            indicator.addEventListener('click', () => {
                switchSlide(index);
                scrollToSlide(index);
            });
        });
        var intervalId = setInterval(nextSlide, 8000);
        // 初始化轮播图
        switchSlide(currentSlideIndex);
        document.addEventListener('DOMContentLoaded', function() {
    // 获取所有的图片元素
    var images = document.querySelectorAll('.carousel-item');

    // 为每个图片添加点击事件监听器
    images.forEach(function(img) {
        img.addEventListener('click', function() {
            // 获取data-target属性的值，即跳转的目标URL
            var targetUrl = img.getAttribute('data-target');
            // 使用window.location.href跳转到目标URL
            window.location.href = targetUrl;
        });
    });
});